package com.springboot.ww.platform.tt.dto;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.List;
import java.util.Optional;

/**
 * @author : liw
 * @date : 2020/11/18 19:34
 */
@JsonIgnoreProperties(ignoreUnknown = true)
@Data
public class TikTokTokenRes implements Serializable {

	/**
	 * 最终可用的token
	 */
	private String token;

	/**
	 * 最终可用的shopId
	 */
	private String shopId;

	private String appKey;

	private String appSecret;

	private String shopCipher;

	@JsonProperty("shopList")
	private List<ShopListBean2> shopListTiktok;

	@JsonIgnoreProperties(ignoreUnknown = true)
	@Data
	public static class ShopListBean2 implements Serializable {
		private String shopId;
		private String shopName;
		@JsonProperty("region")
		private String region;
		@JsonProperty("type")
		private Integer type;
		private String shopCipher;

	}

	public void setShopId(String region) {
		Optional<ShopListBean2> first = shopListTiktok.stream().filter(o ->
				o.getRegion().equalsIgnoreCase(region)).findFirst();
		TikTokTokenRes.ShopListBean2 shopListBean2 = first.get();
		this.shopId = shopListBean2.getShopId();
		this.shopCipher = shopListBean2.getShopCipher();
	}

}
